/**
 * Copyright 2009 Henning Teek, Ingo Renner
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.chigs.web.doku.configpair;

import com.googlecode.chigs.domain.ConfigLocation;
import com.googlecode.chigs.domain.ConfigPair;
import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import java.util.Arrays;
import java.util.List;

/**
 * 
 * @author Ingo Renner
 * @author Henning Teek
 *
 */
@AuthorizeInstantiation("ROLE_USER")
public class EditConfigPairFormularPanel extends Panel {
	public EditConfigPairFormularPanel(String id, IModel<ConfigPair> model, List<ConfigLocation> locations) {
		super(id);
		StringResourceModel lName = new StringResourceModel("name.label", EditConfigPairFormularPanel.this, null);
		add(new Label("name.label", lName));
		add(new TextField<String>("name", new PropertyModel<String>(model.getObject(), "name"))
				.setRequired(true)
				.setLabel(lName));

		StringResourceModel lDefaultData = new StringResourceModel("defaultData.label", EditConfigPairFormularPanel.this, null);
		add(new Label("defaultData.label", lDefaultData));
		add(new TextField<String>("defaultData", new PropertyModel<String>(model.getObject(), "defaultData"))
				.setRequired(false)
				.setLabel(lDefaultData));

		StringResourceModel lMandatory = new StringResourceModel("mandatory.label", EditConfigPairFormularPanel.this, null);
		add(new Label("mandatory.label", lMandatory));
		add(new CheckBox("mandatory", new PropertyModel<Boolean>(model.getObject(), "mandatory"))
				.setRequired(false)
				.setLabel(lMandatory));

		StringResourceModel lType = new StringResourceModel("type.label", EditConfigPairFormularPanel.this, null);
		add(new Label("type.label", lType));
		add(new DropDownChoice<ConfigPair.ConfigPairType>("type", 
				new PropertyModel<ConfigPair.ConfigPairType>(model.getObject(), "type"), 
				Arrays.asList(ConfigPair.ConfigPairType.values()))
			.setRequired(true)
			.setLabel(lType));

		final boolean locreq = true;
		StringResourceModel lConfigLocation = new StringResourceModel("configLocation.label", EditConfigPairFormularPanel.this, null);
		add(new Label("configLocation.label", lConfigLocation));
		add(new DropDownChoice<ConfigLocation>("configLocation", 
				new PropertyModel<ConfigLocation>(model.getObject(), "configLocation"), 
				locations, 
				new ChoiceRenderer<ConfigLocation>("name", "id"))
				.setNullValid(false)
				.setRequired(locreq)
			.setLabel(lConfigLocation));
	}
}

